package Gui;

import java.rmi.RemoteException;

import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.JTextPane;
import javax.swing.SwingUtilities;

import domein.server.IBuilder;

public class MyInvokeLater implements Runnable{

	private JTextPane field;
	private IBuilder builder;
	private int clientID;
	
	public MyInvokeLater (JTextPane field, IBuilder builder2, int id)
	{
		this.field = field;
		this.builder = builder2;
		this.clientID = id;
		
	}
	
	@Override
	public void run() {
		if (!SwingUtilities.isEventDispatchThread())
			throw new IllegalStateException("You should not be calling this logic outside the Swing Event Thread!");
		if (JOptionPane.showConfirmDialog(null, "Er is een nieuwe commit\nWilt u updaten?")==JOptionPane.YES_OPTION)
		{
			try {
				field.setStyledDocument(builder.read(clientID));
				System.out.println(clientID +" updated");
			} catch (RemoteException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		
		}
		
	}

}
